package com.lpit.utils;

import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@Component
public class Tool {

    /*读取流里面字节转换为String*/
    public String readValue(BufferedReader bfReader ) throws IOException {
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = bfReader.readLine()) != null){
            sb.append(line);
        }
        return sb.toString();
    }

    //  获取星号
    public String getPointer(String s) {
        StringBuilder sb = new StringBuilder("*");
        for (int i = 0; i < s.length() - 1; i++) {
            sb.append("*");
        }
        return sb.toString();
    }

    /*排除敏感词，将敏感词修改成*号*/
    public String eliminateSensitive(@NonNull String value, List<String> list){
        for (String s : list) {
            if (value.contains(s)) {
                //将字符保护敏感字的修改成*
                value = value.replaceAll(s, getPointer(s));
            }
        }
        return value;
    }

    /*非空判断*/
    public static boolean isNotEmpty(String obj) {
        return null != obj && !obj.equals("");
    }

}
